package com.bruce.hmily_provider_user.controller;

import com.bruce.hmily_entity.User;
import com.bruce.hmily_provider_user.service.UserService;
import org.dromara.hmily.common.config.HmilyConfig;
import org.dromara.hmily.core.bootstrap.HmilyTransactionBootstrap;
import org.dromara.hmily.core.helper.SpringBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 类注释
 *
 * @author Bruce
 * @date 2021/3/19 3:12 PM
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    //http://localhost:8801/user/update?userId=1&userMoney=10000
    @GetMapping(value = "/update")
    public User update(long userId, double userMoney) {
        User userInfo = userService.findByUserId(userId);
        if(userInfo == null){
            userInfo = new User();
        }
        userInfo.setUserMoney(userMoney);

        return userService.save(userInfo);
    }

    //http://localhost:8801/user/findByUserId?id=1
    @GetMapping(value = "/findByUserId")
    public User findByUserId(long id) {
        return userService.findByUserId(id);
    }

    //测试正常业务
    //http://localhost:8801/user/testDTrans
    @GetMapping(value = "/testDTrans")
    public boolean testDTrans(){
        return userService.testDTrans();
    }
}
